package top.yuki.event;

import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.LivingEntity;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.EntityDeathEvent;
import org.bukkit.inventory.ItemStack;
import top.yuki.LevelWorld;
import top.yuki.data.DataManager;
import top.yuki.data.DayDataManager;
import top.yuki.data.TempDataManage;
import top.yuki.data.WorldManage;

import java.util.List;
import java.util.UUID;

public class onMobDeath implements Listener {
    public DataManager dataManage;
    private final TempDataManage tempDataManage;
    private final DayDataManager dayDataManager;
    private final WorldManage worldManage;
    private final ConfigurationSection config;
    public onMobDeath (LevelWorld lw){
        this.dataManage = LevelWorld.dataManage;
        this.tempDataManage = LevelWorld.tempDataManage;
        this.dayDataManager = LevelWorld.dayDataManager;
        this.worldManage = LevelWorld.worldManage;
        this.config = lw.getConfig();
    }

    @EventHandler
    public void mobDeath(EntityDeathEvent event) {

        String worldName = event.getEntity().getLocation().getWorld().getName();
        int worldLevel = worldManage.getWorldLevel(worldName);
        Drop(event,worldLevel);
    }

    public void Drop(EntityDeathEvent event,int worldLevel){
        List<ItemStack> drops = event.getDrops();


        double worldDropXpMagnification = Double.valueOf(String.valueOf(config.get("worldDropXpMagnification." + worldLevel)));
        double worldDropItemMagnification = Double.valueOf(String.valueOf(config.get("worldDropItemMagnification." + worldLevel))) ;

        event.setDroppedExp((int) (event.getDroppedExp()*worldDropXpMagnification));
        LivingEntity entity = event.getEntity();
        for (ItemStack drop : drops) {
            for (int i = 0; i < worldDropItemMagnification-1; i++) {

                entity.getLocation().getWorld().dropItem(entity.getLocation(),drop);
            }

        }
//        entity.getLocation().getWorld().dropItem(entity.getLocation(), new ItemStack(Material.DIAMOND_SWORD, 1));



    }
}
